// 题意：放数字，满足上下左右比当前位置数大的数字的个数限制
//
// 题解：简单搜索，剪枝就行。
//

#include <iostream>

int const maxn = 5;
bool vis[maxn][maxn];
int a[maxn][maxn];
int b[maxn][maxn];
int ab[maxn][maxn];
int n;

bool dfs(int deep)
{
	/*
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) std::cout << ab[i][j] << ' ';
		std::cout << "  ";
		for (int j = 0; j < n; j++) std::cout << a[i][j] << ' ';
		std::cout << '\n';
	}
	std::cout << '\n'; std::cout << '\n';
	*/

	if (deep == n*n) {
		for (int i = 0; i < n; i++)
			if (ab[n-1][i] != b[n-1][i]) return false;
		return true;
	}

	int x = deep / n, y = deep % n;
	for (int i = 0; i <= 9; i++) {
		a[x][y] = i;
		int up = 0, left = 0, now = 0;
		if (deep >= n) {
			up = (i > a[x-1][y]);
			now += (a[x-1][y] > i);
			if (ab[x-1][y] + up != b[x-1][y]) continue;
		}
		if (deep % n) {
			left = (i > a[x][y-1]);
			now += (a[x][y-1] > i);
			if (ab[x][y-1] + left > b[x][y-1]) continue;
		}
		ab[x][y] = now;
		if (deep >= n) ab[x-1][y] += up;
		if (deep % n) ab[x][y-1] += left;
		if (dfs(deep + 1)) return true;
		if (deep >= n) ab[x-1][y] -= up;
		if (deep % n) ab[x][y-1] -= left;
	}
	return false;
}

int main()
{
	std::cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) std::cin >> b[i][j];

	if (!dfs(0)) {
		std::cout << "NO SOLUTION\n";
	} else {
		for (int i = 0; i < n; i++) {
			std::cout << a[i][0];
			for (int j = 1; j < n; j++) std::cout << ' ' << a[i][j];
			std::cout << '\n';
		}
	}
}

